Page({
  data: {
    currentTab: 'order', 
    orderList: [],
    page: 1,
    pageSize: 10,
    total: 0
  },

  viewOrderDetails(event) {
    const orderId = event.currentTarget.dataset.orderid;
    // Implement logic to display order details for the selected order
  },

  deleteOrder(event) {
    const orderId = event.currentTarget.dataset.orderid;
    // Implement logic to delete the selected order
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getOrderList()
  },

  getOrderList(){
    wx.showLoading({
      title: '数据加载中...',
    })
    
    wx.request({
      url: `http://localhost:8080/admin/order/list1`,
      method: 'Get',
      data:{
        start: this.data.page,
        pageSize: this.data.pageSize
      },

      success: (res) => {
        this.setData({
          orderList: res.data.orderList,
          total: res.data.total
        });
        // if (res.data && Array.isArray(res.data.message)) {
        //   this.setData({
        //     orderList: [...this.data.orderList, ...res.data.message],
        //     total: res.header['X-Total-Count'] * 1
        //   });
        // } else {
        //   console.error('Unexpected data format:', res.data);
        //   // Log the complete response for debugging purposes
        //   console.log('Complete response:', res);
        // }
      },

      complete: () => {
        wx.hideLoading()
        this.setData({ isloding: false })
        }
      })
    },

    evaluate(){
      wx.navigateTo({
        url: '/pages/evaluation/evaluation',
      })
    },

    viewOrderDetails(){
      wx.navigateTo({
        url: '/pages/orderInformation/orderInformation',
      })
    },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.setData({
      page: 1,
      total: 0
    });
    this.getOrderList();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    if (this.data.orderList.length >= this.data.total) {
      return wx.showToast({
        title: '订单加载完毕',
        icon: 'none'
      });
    }
    this.setData({
      page: this.data.page + 1
    });

    this.getOrderList();
  },

  switchTab(event) {
    const targetTab = event.currentTarget.dataset.tab;
    if (this.data.currentTab !== targetTab) {
      wx.switchTab({
        url: `/pages/${targetTab}/${targetTab}`
      });
    }
  }
})